package com.caiyi.financial.nirvana.sms.server;

public class LongMessageEntity {

    private long startTime;

    private int serial;
    private int total;
    private String phone;
    private String[] contents;
    private Long[] messageIds;

    public LongMessageEntity(int serial, int total, String phone) {
        startTime = System.currentTimeMillis();
        this.serial = serial;
        this.total = total;
        this.phone = phone;
        contents = new String[total];
        messageIds = new Long[total];
    }

    public void addMessage(int number, Long messageId, String content) {
        if (number > total || number < 1) {
            return;
        }
        messageIds[number - 1] = messageId;
        contents[number - 1] = content;
    }

    public boolean isFinish() {
        for (int i = 0; i < total; i++) {
            if (null == messageIds[i]) {
                return false;
            }
        }
        return true;
    }

    public String getFullContent() {
        StringBuffer stb = new StringBuffer();
        for (int i = 0; i < total; i++) {
            stb.append(contents[i]);
        }
        return stb.toString();
    }

    public String getKey() {
        return phone + serial;
    }

    @Override
    public String toString() {
        StringBuilder stb = new StringBuilder();
        stb.append("S:").append(serial).append(" ");
        stb.append("T:").append(total).append(" ");
        stb.append("phone:").append(phone).append(" ");
        stb.append("messageIds[");
        for (int i = 0; i < total; i++) {
            stb.append(messageIds[i]).append(" ");
        }
        stb.append("]");
        return stb.toString();
    }

    public long getStartTime() {
        return startTime;
    }

    public int getSerial() {
        return serial;
    }

    public int getTotal() {
        return total;
    }

    public String getPhone() {
        return phone;
    }

    public Long[] getMessageIds() {
        return messageIds;
    }

}
